from __future__ import annotations

from dataclasses import dataclass


@dataclass
class InsulatorCompensation:
    added_length_m: float
    sag_change_m: float
    note: str


def compensate_strain_insulator(length_m: float, angle_deg: float, span_m: float, unit_weight_kN_m: float, tension_kN: float) -> InsulatorCompensation:
    """耐张串补偿对线长与弧垂的影响（近似）。

    - 增加线长≈串长的水平投影
    - 弧垂变化按 df ≈ (∂f/∂l)·Δl ≈ (w·l/4H)·Δl
    """

    import math
    delta_l = length_m * math.cos(math.radians(angle_deg))
    df = (unit_weight_kN_m * span_m / max(1e-6, 4.0 * tension_kN)) * delta_l
    return InsulatorCompensation(added_length_m=delta_l, sag_change_m=df, note="抛物线近似")


